home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / netconf / thishost.c < prev    next >
C/C++ Source or Header  |  1996-03-09  |  1KB  |  82 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <stdarg.h>
  5. #include <netdb.h>
  6. #include "netconf.h"
  7. #include "../xconf/xconf.h"
  8.  
  9.  
  10. PUBLIC THISHOST::THISHOST()
  11. {
  12.     name1 = NULL;
  13.     ip_num[0] = '\0';
  14.     is_config = 0;
  15.     char status[1000];
  16.     struct hostent *ent = netconf_netok(status);
  17.     if (ent != NULL){
  18.         name1 = strdup(ent->h_name);
  19.         devices_ip2a (ent,ip_num);
  20.         is_config = 1;
  21.     }else{
  22.         name1 = strdup("");
  23.         #ifdef TEST
  24.             printf ("status :%s:\n",status);
  25.         #endif
  26.     }
  27. }
  28. PUBLIC THISHOST::~THISHOST()
  29. {
  30.     free (name1);
  31.     ip_num[0] = '\0';
  32.     is_config = 0;
  33. }
  34.  
  35. /*
  36.     Accept a new name for the host.
  37. */
  38. PUBLIC void THISHOST::setname1(const char *newname1)
  39. {
  40.     free(name1);
  41.     name1 = strdup(newname1);
  42. }
  43.  
  44. /*
  45.     Return of the IP number of this host
  46. */
  47. PUBLIC const char *THISHOST::getipnum(int )
  48. {
  49.     return ip_num;
  50. }
  51. /*
  52.     Return of the primary name of this host
  53. */
  54. PUBLIC const char *THISHOST::getname1()
  55. {
  56.     return name1;
  57. }
  58. /*
  59.     Return != 0 if the local hostname is correctly configured
  60. */
  61. PUBLIC int THISHOST::configok()
  62. {
  63.     return is_config;
  64. }
  65.  
  66.  
  67. #ifdef TEST
  68.  
  69. int main (int argc, char *argv[])
  70. {
  71.     THISHOST host;
  72.     if (host.configok()){
  73.         printf (":%s: -> :%s:\n",host.getname1(),host.getipnum(0));
  74.     }else{
  75.         printf ("Pas configurer\n");
  76.     }
  77.     return 0;
  78. }
  79.  
  80. #endif
  81.  
  82.